package com.snailct.bpp.router.datachange;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
import org.jdom.Element;

import java.util.ArrayList;

/**
 * Created by huangxa on 2016/5/22.
 */
public class Util {
    private static final Log logger = LogFactory.getLog(Util.class);
    public static int getElementLevel(Document doc, Element node){
        return 0;
    }
    public static void createTable(String tableName,ArrayList<String> strArray){
        String sqlStr = "DROP TABLE IF EXISTS SOA_AUTO_"+tableName+";\n";
        DaoOperation.execute(sqlStr);
        sqlStr = "";
        sqlStr+="create table SOA_AUTO_"+tableName+" ";
        sqlStr+="(auto_id bigint NOT NULL PRIMARY key AUTO_INCREMENT,";
        for(int j=0;j<strArray.size();j++){
            String str = strArray.get(j);
            if(j==strArray.size()-1){
                sqlStr+=str+" varchar(80) DEFAULT NULL)";
            }else{
                sqlStr+=str+" varchar(80) DEFAULT NULL,";
            }
        }
        sqlStr+=";";
        System.out.println(sqlStr);
        logger.info("执行SQL为:"+sqlStr);
        DaoOperation.execute(sqlStr);
    }
    public static void formElementToMessageNode(Element element,MessageNode node){
        node.setCurrentElementName(element.getChildText("currentElementName"));
        node.setCurrentElementLevel(element.getChildText("currentElementLevel"));
        node.setParentElementName(element.getChildText("parentElementName"));
        node.setIsBottom(element.getChildText("isBottom"));
    }
}
